### FRANCE RENAMING AND RECODING ## 
### FRANCE RENAMING AND RECODING ## 
### FRANCE RENAMING AND RECODING ## 
setwd("set working directory")

library(haven)

FR_W1 <- read_sav("load panel wave 1")
FR_W2 <- read_sav("load panel wave 2")
FR_W3 <- read_sav("load panel wave 3")
FR_W4 <- read_sav("load panel wave 4")
FR_W5 <- read_sav("load panel wave 5")

FR_W1 <- FR_W1 %>% 
  select(GUNQID:cos1_w1_4)

FR_W2 <- FR_W2 %>% 
  select(GUNQID:cos1_w2_4)

FR_W3 <- FR_W3 %>% 
  select(GUNQID:cos1_w3_4)

FR_W4 <- FR_W4 %>% 
  select(GUNQID:cos1_w4_4)

FR_W1 <- FR_W1 %>%
  rename_with(~paste0(sub("_w1*", "", .)), -1)

FR_W2 <- FR_W2 %>%
  rename_with(~paste0(sub("_w2*", "", .)), -1)

FR_W3 <- FR_W3 %>%
  rename_with(~paste0(sub("_w3*", "", .)), -1)

FR_W4 <- FR_W4 %>%
  rename_with(~paste0(sub("_w4*", "", .)), -1)

data.comp <- compare_df_cols(FR_W1, FR_W2, FR_W3, FR_W4)


## education and education_recode ## 

table(FR_W1$education_recode) # Not available
table(FR_W1$education) # not available


table(FR_W2$education) # 1 to 7

table(FR_W3$education_recode) # 1 to 9 

table(FR_W4$education_recode) # 1 to 7


## rename income variable ## 


table(FR_W1$income) # Missing

table(FR_W2$income) # from 1 to 16

table(FR_W3$income) # from 1 to 16

table(FR_W4$income) # from 1 to 16




### FRANCE - WAVE 1 ### 
### FRANCE - WAVE 1 ### 
### FRANCE - WAVE 1 ### 
### FRANCE - WAVE 1 ### 

names(FR_W1)

# education_recode, 
# income, 
# pb4_politicalscale,
# ppol_partyid, 
# religion

table(FR_W1$education_recode) # ADDED 
table(FR_W1$income) # ADDED 
table(FR_W1$pb4) # ADDED 
table(FR_W1$education_recode) # ADDED 


# pb4_politicalscale,

table(FR_W2$pb4_politicalscale) ## wave 2 

table(FR_W1$pb4) # rename this variable 

FR_W1 <- FR_W1 %>% 
  rename(pb4_politicalscale = pb4)

# ppol_partyid, 

table(FR_W2$ppol_partyid)
table(FR_W1$ppol)

FR_W1 <- FR_W1 %>% 
  rename(ppol_partyid = ppol)

## track7a 
table(FR_W1$track7a_w1) 

FR_W1 <- FR_W1 %>% 
  rename(track7a = track7a_w1)


## CHECKING DK 
table(FR_W1$track8_w1_1)
table(FR_W1$track8_w1_2)
table(FR_W1$track8_w1_3)
table(FR_W1$track8_w1_4)
table(FR_W1$track8_w1_5)

table(FR_W1$track9_w1) ## change DK 12 to 11. 

table(FR_W1$track10_w1)

# purpose_w1
table(FR_W1$purpose_w1)

FR_W1 <- FR_W1 %>%
  mutate(purpose_w1 = purpose_w1-1)

# cost5_w1
table(FR_W1$cost5_w1)

FR_W1 <- FR_W1 %>%
  mutate(cost5_w1 = cost5_w1-1)

# trust1_w1
table(FR_W1$trust1_w1) # ALL GOOD 


# trust2_w1

table(FR_W1$trust2_w1) # ALL GOOD 

# trust3_w1
table(FR_W1$trust3_w1)

# dem1_w1
table(FR_W1$dem1_w1)

FR_W1 <- FR_W1 %>%
  mutate(dem1_w1 = dem1_w1-1)


write_sav(FR_W1, "save panel 1") 


### WAVE 2 - FRANCE ## 
### WAVE 2 - FRANCE ## 
### WAVE 2 - FRANCE ## 
### WAVE 2 - FRANCE ##

#-100 recoded as "Not answered"; 
# education rename to education_recode; THEY HAVE DIFFERENT CATEGORIES. 
# check if education_recode that goes from 1 to 9 can be recoded from 1 to 7
table(FR_W2$education)

## check 997
table(FR_W2$track1_w2_1) # ADD 997 TO THE CODEBOOK

table(FR_W2$track7a_w2) 

FR_W2 <- FR_W2 %>% 
  rename(track7_w2 = track7a_w2)

table(FR_W2$track7_w2)

## CHECKING DK 
table(FR_W2$track8_w2_1) # SUBSTRACT - 1
table(FR_W2$track8_w2_2) # SUBSTRACT - 1
table(FR_W2$track8_w2_3) # SUBSTRACT - 1
table(FR_W2$track8_w2_4) # SUBSTRACT - 1
table(FR_W2$track8_w2_5) # SUBSTRACT - 1


FR_W2 <- FR_W2 %>%
  mutate(track8_w2_1 = track8_w2_1-1,
         track8_w2_2 = track8_w2_2-1,
         track8_w2_3 = track8_w2_3-1,
         track8_w2_4 = track8_w2_4-1,
         track8_w2_5 = track8_w2_5-1)

table(FR_W2$track9_w2) ## RECODE DK 12 to 11. 

FR_W2 <- FR_W2 %>%
  mutate(track9_w2 = dplyr::recode(track9_w2, '12'=11))

table(FR_W2$track10_w2) # ALL GOOD

# purpose_w2
table(FR_W2$purpose_w2) # SUBSTRACT - 1

FR_W2 <- FR_W2 %>%
  mutate(purpose_w2 = purpose_w2-1)

# cost5_w2
table(FR_W2$cost5_w2) # SUBSTRACT - 1

FR_W2 <- FR_W2 %>%
  mutate(cost5_w2 = cost5_w2-1)

# trust1_w2
table(FR_W2$trust1_w2) # ALL GOOD 


# trust2_w2

table(FR_W2$trust2_w2) # ALL GOOD 

# trust3_w2
table(FR_W2$trust3_w2) # ALL GOOD 

# dem1_w2
table(FR_W2$dem1_w2) # SUBSTRACT - 1

FR_W2 <- FR_W2 %>%
  mutate(dem1_w2 = dem1_w2-1)


write_sav(FR_W2, "save panel") 

### WAVE 3 - FRANCE ## 
### WAVE 3 - FRANCE ## 
### WAVE 3 - FRANCE ## 
### WAVE 3 - FRANCE ##

## check 997
table(FR_W3$track1_w3_1) # RECODE 997 AND CHANGE CODEBOOK
table(FR_W3$track1_w3_2)  # RECODE 997 AND CHANGE CODEBOOK
table(FR_W3$track1_w3_3)  # RECODE 997 AND CHANGE CODEBOOK

FR_W3 <- FR_W3 %>%
  mutate(track1_w3_1 = dplyr::recode(track1_w3_1, '5'=997),
         track1_w3_2 = dplyr::recode(track1_w3_2, '5'=997),
         track1_w3_3 = dplyr::recode(track1_w3_3, '5'=997),
         track1_w3_4 = dplyr::recode(track1_w3_4, '5'=997),
         track1_w3_5 = dplyr::recode(track1_w3_5, '5'=997),
         track1_w3_6 = dplyr::recode(track1_w3_6, '5'=997),
         track1_w3_7 = dplyr::recode(track1_w3_7, '5'=997),
         track1_w3_8 = dplyr::recode(track1_w3_8, '5'=997),
         track1_w3_9 = dplyr::recode(track1_w3_9, '5'=997),
         track1_w3_10 = dplyr::recode(track1_w3_10, '5'=997))

table(FR_W3$track7a_w3) 

FR_W3 <- FR_W3 %>% 
  rename(track7_w3 = track7a_w3)

table(FR_W3$track7_w3)

## CHECKING DK 
table(FR_W3$track8_w3_1) # SUBSTRACT -1 
table(FR_W3$track8_w3_2) # SUBSTRACT -1 
table(FR_W3$track8_w3_3) # SUBSTRACT -1 
table(FR_W3$track8_w3_4) # SUBSTRACT -1 
table(FR_W3$track8_w3_5) # SUBSTRACT -1 


FR_W3 <- FR_W3 %>%
  mutate(track8_w3_1 = track8_w3_1-1,
         track8_w3_2 = track8_w3_2-1,
         track8_w3_3 = track8_w3_3-1,
         track8_w3_4 = track8_w3_4-1,
         track8_w3_5 = track8_w3_5-1)

table(FR_W3$track9_w3) # SUBSTRACT -1 

FR_W3 <- FR_W3 %>%
  mutate(track9_w3 = track9_w3-1)

table(FR_W3$track10_w3) # ALL GOOD

# purpose_w3
table(FR_W3$purpose_w3) # SUBSTRACT -1 

FR_W3 <- FR_W3 %>%
  mutate(purpose_w3 = purpose_w3-1)

# cost5_w3
table(FR_W3$cost5_w3) # SUBSTRACT -1 

FR_W3 <- FR_W3 %>%
  mutate(cost5_w3 = cost5_w3-1)

# trust1_w3
table(FR_W3$trust1_w3) # SUBSTRACT -1 

FR_W3 <- FR_W3 %>%
  mutate(trust1_w3 = trust1_w3-1)

# trust2_w3

table(FR_W3$trust2_w3)  # SUBSTRACT -1 

FR_W3 <- FR_W3 %>%
  mutate(trust2_w3 = trust2_w3-1)

# trust3_w3
table(FR_W3$trust3_w3) # SUBSTRACT -1

FR_W3 <- FR_W3 %>%
  mutate(trust3_w3 = trust3_w3-1)

# dem1_w3
table(FR_W3$dem1_w3) # SUBSTRACT -1

FR_W3 <- FR_W3 %>%
  mutate(dem1_w3 = dem1_w3-1)

FR_W3$dnut_w3

FR_W3 <- FR_W3 %>%
  mutate(dnut_w3 = dnut_w3-1)

write_sav(FR_W3, "save panel") 


### WAVE 4 - FRANCE ## 
### WAVE 4 - FRANCE ## 
### WAVE 4 - FRANCE ## 
### WAVE 4 - FRANCE ##

## check 997
table(FR_W4$track1_w4_1) # ADD 997 TO THE CODEBOOK

table(FR_W4$track7a_w4) 

FR_W4 <- FR_W4 %>% 
  rename(track7_w4 = track7a_w4)

table(FR_W4$track7_w4)

## CHECKING DK 
table(FR_W4$track8_w4_1) # SUBSTRACT -1
table(FR_W4$track8_w4_2) # SUBSTRACT -1
table(FR_W4$track8_w4_3) # SUBSTRACT -1
table(FR_W4$track8_w4_4) # SUBSTRACT -1
table(FR_W4$track8_w4_5) # SUBSTRACT -1


FR_W4 <- FR_W4 %>%
  mutate(track8_w4_1 = track8_w4_1-1,
         track8_w4_2 = track8_w4_2-1,
         track8_w4_3 = track8_w4_3-1,
         track8_w4_4 = track8_w4_4-1,
         track8_w4_5 = track8_w4_5-1)

table(FR_W4$track9_w4) # RECODE 12 TO 11  

FR_W4 <- FR_W4 %>%
  mutate(track9_w4 = dplyr::recode(track9_w4, '12'=11))

table(FR_W4$track10_w4) 

# purpose_w4
table(FR_W4$purpose_w4) # SUBSTRACT -1

FR_W4 <- FR_W4 %>%
  mutate(purpose_w4 = purpose_w4-1)

# cost5_w4
table(FR_W4$cost5_w4) # SUBSTRACT -1

FR_W4 <- FR_W4 %>%
  mutate(cost5_w4 = cost5_w4-1)

# trust1_w4
table(FR_W4$trust1_w4)  

FR_W4 <- FR_W4 %>%
  mutate(trust1_w4 = dplyr::recode(trust1_w4, '12'=11))


# trust2_w4

table(FR_W4$trust2_w4) # ALL GOOD

# trust3_w4
table(FR_W4$trust3_w4) # ALL GOOD  

# dem1_w4
table(FR_W4$dem1_w4) # SUBSTRACT -1

FR_W4 <- FR_W4 %>%
  mutate(dem1_w4 = dem1_w4-1)

table(FR_W4$eff1_w4)

table(FR_W4$dnut_w4)

FR_W4 <- FR_W4 %>%
  mutate(dnut_w4 = dnut_w4-1)


write_sav(FR_W4, "save panel") 

### WAVE 5 - FRANCE ## 
### WAVE 5 - FRANCE ## 
### WAVE 5 - FRANCE ## 
### WAVE 5 - FRANCE ##

## check 997
table(FR_W5$track1_w5_1) # ADD 997 TO THE CODEBOOK

table(FR_W5$track7a_w5) 

FR_W5 <- FR_W5 %>% 
  rename(track7_w5 = track7a_w5)

table(FR_W5$track7_w5)

## CHECKING DK 
table(FR_W5$track8_w5_1) # SUBSTRACT -1
table(FR_W5$track8_w5_2) # SUBSTRACT -1
table(FR_W5$track8_w5_3) # SUBSTRACT -1
table(FR_W5$track8_w5_4) # SUBSTRACT -1
table(FR_W5$track8_w5_5) # SUBSTRACT -1


FR_W5 <- FR_W5 %>%
  mutate(track8_w5_1 = track8_w5_1-1,
         track8_w5_2 = track8_w5_2-1,
         track8_w5_3 = track8_w5_3-1,
         track8_w5_4 = track8_w5_4-1,
         track8_w5_5 = track8_w5_5-1)

table(FR_W5$track9_w5) # RECODE 12 TO 11  

FR_W5 <- FR_W5 %>%
  mutate(track9_w5 = dplyr::recode(track9_w5, '12'=11))

table(FR_W5$track10_w5) 


# purpose_w5
table(FR_W5$purpose_w5) # SUBSTRACT -1

FR_W5 <- FR_W5 %>%
  mutate(purpose_w5 = purpose_w5-1)

# cost5_w5
table(FR_W5$cost5_w5) # SUBSTRACT -1

FR_W5 <- FR_W5 %>%
  mutate(cost5_w5 = cost5_w5-1)

# trust1_w5
table(FR_W5$trust1_w5) #11 don't neeed  

# trust2_w5

table(FR_W5$trust2_w5) # ALL GOOD

# trust3_w5
table(FR_W5$trust3_w5) # ALL GOOD  

# dem1_w5
table(FR_W5$dem1_w5) # SUBSTRACT -1

FR_W5 <- FR_W5 %>%
  mutate(dem1_w5 = dem1_w5-1)

table(FR_W5$eff1_w5)

table(FR_W5$dnut_w5) # not available

FR_W5 <- FR_W5 %>%
  mutate(dnut_w5 = dnut_w5-1)

FR_W5 <- FR_W5 %>%
  rename(WeightPanelW5 = weight)

write_sav(FR_W5, "save panel") 